$(function () {
  //搜索
  $(".search_bar>input").on("keyup", function (e) {
    if (e.keyCode == 13) {
      // console.log($(this).val());
      if ($(this).val().trim() == "") {
        alert("没输入呢");
        return;
      }

      $(".song_list").html("BUG音乐搜索中...");
      $.ajax({
        type: "get",
        url: "https://autumnfish.cn/search",
        data: {
          keywords: $(this).val().trim(),
        },
        success: function (mYdata) {
          $(".song_list").html(template("musiclis", mYdata));
        },
      });
    }
  });

  // lsi点击事件

  $(".song_list").on("click", "li", function () {
    $.ajax({
      type: "get",
      url: "https://autumnfish.cn/song/url",
      data: {
        id: $(this).attr("data-id"),
      },
      success: function (mYdata) {
        // console.log(mYdata);
        $(".audio_con .myaudio").attr("src", mYdata.data[0].url);
      },
    });
    //展示评论
    $.ajax({
      type: "get",
      url: "https://autumnfish.cn/comment/music",
      data: {
        id: $(this).attr("data-id"),
      },
      success: function (mydata) {
        $(".comment_list>div").html(template("comments", mydata));
      },
    });

    //封面
    $.ajax({
      type: "get",
      url: "https://autumnfish.cn/song/detail",
      data: {
        ids: $(this).attr("data-id"),
      },
      success: function (mydata) {
        $(".cover").attr("src", mydata.songs[0].al.picUrl);
      },
    });
  });

  //小杆杆同步点击事件
  $(".audio_con>audio").on("play", function () {
    $(".player_con>img").addClass("playing");
  });
  $(".audio_con>audio").on("pause", function () {
    $(".player_con>img").removeClass("playing");
  });
});
